package com.gdupt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gdupt.entity.DataDictionary;
import com.gdupt.entity.vo.ResponseData;
import com.gdupt.service.IDataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dataDictionary")
public class DataDictionaryController {
    @Autowired
    private IDataDictionaryService iDataDictionaryService;

    @RequestMapping("/search")
    public ResponseData search(Page page,@RequestParam(value ="dataType",required = false) String dataType, @RequestParam(value = "dataEntry",required = false) String dataEntry,@RequestParam(value = "dataValue",required = false) String dataValue){
        List<DataDictionary> list = iDataDictionaryService.search(page ,dataType,dataEntry,dataValue);
        return ResponseData.okData(page.getTotal(),list);
    }

    @PostMapping("/del/{id}")
    public ResponseData del(@PathVariable("id") int id){
        boolean flg = iDataDictionaryService.del(id);
        if(flg){
            return ResponseData.okMsg("删除成功！！");
        }
        return ResponseData.failMsg("删除失败！！");
    }

    @PostMapping("/add")
    public  ResponseData add(DataDictionary data){
        //System.out.println(data);
        boolean flg = iDataDictionaryService.add(data);
        if(flg){
            return ResponseData.okMsg("操作成功！！");
        }
        return ResponseData.failMsg("操作失败！！");

    }

    @PostMapping("/edit")
    public  ResponseData edit(DataDictionary data){
        //System.out.println(data);
        boolean flg = iDataDictionaryService.edit(data);
        if(flg){
            return ResponseData.okMsg("操作成功！！");
        }
        return ResponseData.failMsg("操作失败！！");
    }
//    @GetMapping("/findId")
//    public ResponseData findId( @RequestParam(value = "id",required = false) int id){
//        boolean flg = iDataDictionaryService.findId(id);
//        if(flg){
//            return ResponseData.okMsg("该id已有");
//        }
//        return ResponseData.failMsg("");
//    }
}
